package com.geovis.emergency.spd.controller.app;


import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.common.core.controller.BaseController;
import com.geovis.common.mybatis.page.PageParam;
import com.geovis.common.mybatis.page.PageResult;
import com.geovis.emergency.spd.biz.agora.AgoraTokenDTO;
import com.geovis.emergency.spd.biz.app.service.AppDiscussService;
import com.geovis.emergency.spd.biz.pc.service.IPcDiscussService;
import com.geovis.emergency.spd.biz.system.service.ISystemDeptService;
import com.geovis.emergency.spd.entity.app.dto.AppDiscussDTO;
import com.geovis.emergency.spd.entity.app.dto.AppDiscussSaveDTO;
import com.geovis.emergency.spd.entity.app.enums.AppDiscussTypeEnum;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussQueryDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussSaveDTO;
import com.geovis.emergency.spd.entity.system.pojo.vo.SystemUserVo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 处置app-研判会商 前端控制器
 * </p>
 *
 * @author 曾德实
 * @since 2022-05-01
 */
@RestController
@RequestMapping("/app/appDiscuss")
@RequiredArgsConstructor
@Api(value = "处置app-研判会商接口", tags = "处置app-研判会商接口")
@Slf4j
@Validated
public class AppDiscussController  {

    private final ISystemDeptService systemDeptService;

    private final AppDiscussService appDiscussService;

    @ApiOperation(value = "创建会议", notes = "创建会议")
    @PostMapping({"/create"})
    public Result<String> create(@RequestBody AppDiscussSaveDTO saveDTO) {

        if(CollectionUtils.isEmpty(saveDTO.getStaffIdList()))
        {
            return Result.failed("会议人员列表不能为空");
        }
        appDiscussService.save(saveDTO);
        return Result.ok();
    }

    @ApiOperation(value = "进入会议", notes = "进入会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "appDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/join/{appDiscussId}"})
    public Result<AgoraTokenDTO> join(@PathVariable("appDiscussId") String appDiscussId) {
        return Result.ok(appDiscussService.join(appDiscussId));
    }

    @ApiOperation(value = "结束会议", notes = "结束会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "appDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/finish/{appDiscussId}"})
    public Result<String> finish(@PathVariable("appDiscussId") String appDiscussId) {
        appDiscussService.finish(appDiscussId);
        return Result.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "离开会议", notes = "离开会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "appDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/leave/{appDiscussId}"})
    public Result<String> leave(@PathVariable("appDiscussId") String appDiscussId) {
        appDiscussService.leave(appDiscussId);
        return Result.ok();
    }

    @ApiOperation(value = "会议列表", notes = "会议列表")
    @GetMapping("/getList")
    public Result<List<AppDiscussDTO>> getList(AppDiscussTypeEnum discussType) {
        return Result.ok(appDiscussService.getList(discussType));
    }

    @ApiOperation(value = "选择参加会议的人员", notes = "选择参加会议的人员")
    @GetMapping("/queryUsers")
    public Result<List<SystemUserVo>> queryUsers(String deptId) {
        return Result.ok(systemDeptService.queryAllChildDeptUsers(deptId));
    }



}
